<!DOCTYPE html>
<html>
<head>
    <title>AI Chat</title>
    <style>
        .container {
            width: 800px;
            margin: 50px auto;
        }
        .input-area {
            margin-bottom: 20px;
        }
        textarea {
            width: 100%;
            height: 100px;
            margin-bottom: 10px;
        }
        .response-area {
            border: 1px solid #ccc;
            padding: 10px;
            min-height: 200px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="input-area">
            <textarea id="questionInput" placeholder="请输入您的问题..."></textarea>
            <button onclick="sendQuestion()">发送</button>
        </div>
        <div class="response-area" id="responseArea">
            <!-- 答案将显示在这里 -->
        </div>
    </div>

    <script>
        function sendQuestion() {
            const question = document.getElementById('questionInput').value;
            if (!question) {
                alert('请输入问题');
                return;
            }
            
            fetch('/ai/chat', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    question: question
                })
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById('responseArea').innerText = data.data;
            })
            .catch(error => {
                console.error('Error:', error);
                alert('发送请求失败');
            });
        }
    </script>
</body>
</html> 